package com.team9.fitness.entity;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

/**
 * 帖子评论实体
 * 
 * 存储帖子评论的完整信息：
 * - 基本信息：评论内容、创建时间
 * - 统计信息：点赞数量
 * - 状态信息：当前用户是否点赞
 * - 关联信息：帖子ID、用户ID
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class PostComment {

    private Long id;

    private Long postId;

    private Long userId;

    /**
     * 父评论ID，用于嵌套评论
     */
    private Long parentId;

    /**
     * 根评论ID，用于嵌套评论
     */
    private Long rootId;

    /**
     * 评论作者用户名
     */
    private String author;

    /**
     * 评论内容
     */
    private String content;

    /**
     * 点赞数量
     */
    private Integer likeCount;

    /**
     * 当前用户是否点赞
     */
    private Boolean isLiked;

    /**
     * 是否已删除
     */
    private Boolean isDeleted;

    private LocalDateTime createdAt;

    public void setCreatedAtIfNull() {
        if (createdAt == null) {
            createdAt = LocalDateTime.now();
        }
    }

    /**
     * 初始化统计字段
     */
    public void initializeCounts() {
        if (this.likeCount == null) {
            this.likeCount = 0;
        }
        if (this.isLiked == null) {
            this.isLiked = false;
        }
        if (this.isDeleted == null) {
            this.isDeleted = false;
        }
    }
}
